// ======================================================================
// Copyright (C) 2013 Hell-Prototypes. / www.hellprototypes.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// ======================================================================
#include "plot_grid.h"
#include "qwt_painter.h"
#include "qwt_text.h"
#include "qwt_scale_map.h"
#include "qwt_scale_div.h"
#include "qwt_math.h"
#include <qpainter.h>
#include <qpen.h>
#include <QDebug>

plot_grid::plot_grid()
{
    m_pen.setColor(QColor(102,102,102));
    m_pen.setStyle(Qt::DotLine);
}
plot_grid::~plot_grid()
{
}

void plot_grid::draw( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect ) const
{
    Q_UNUSED (xMap);
    Q_UNUSED (yMap);

    int l = canvasRect.left() + 1;//1
    int r = canvasRect.right() - 4;
    int b = canvasRect.bottom() - 4;
    int t = canvasRect.top() + 1;//1

    painter->setPen(m_pen);

    QwtPainter::drawRect(painter, l, t, r, b);

    double pos = l;
    double step = r/10;
    for(int i=0; i<9; i++) {
        pos += step;
        QwtPainter::drawLine( painter, qRound(pos), t, qRound(pos), b+1 );
    }
    pos = t+2;
    step = b/8;
    for(int i=0; i<7; i++) {
        pos += step;
        QwtPainter::drawLine( painter, l, qRound(pos), r+1, qRound(pos) );
    }
}
